home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / AimTaskMenu.xul < prev    next >
Encoding:
Extensible Markup Language  |  2002-06-24  |  10.9 KB  |  311 lines

  1. <?xml version="1.0"?>
  2.  
  3. <?xml-stylesheet href="chrome://aim/skin/aimTasksOverlay.css" type="text/css"?>
  4.  
  5. <!DOCTYPE overlay SYSTEM "chrome://aim/locale/AimTaskMenu.dtd" >
  6.  
  7. <overlay id="aimTaskMenuID"
  8.          xmlns:html="http://www.w3.org/1999/xhtml"
  9.          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  10.   
  11.   <script language="JavaScript" src="chrome://aim/content/aimHelpers.js" />
  12.   <script language="JavaScript" src="chrome://aim/content/AimSession.js" />
  13.   <script language="JavaScript" src="chrome://aim/content/Aim.js" /> 
  14.  
  15.  
  16.   <keyset id="tasksKeys">
  17.     <key id="key_im"  key="&IMCmd.commandkey;" command="Tasks:IM" modifiers="accel"/>
  18.   </keyset>
  19.  
  20.  
  21.   <commandset id="tasksCommands">
  22.     <command id="Tasks:IM" oncommand="toOpenWindowByType('Aim:AimApp', 'chrome://aim/content/App.xul');"/>
  23.   </commandset>
  24.   
  25.   
  26.   <menupopup id="windowPopup">
  27.     <menuitem id="IMMenuItem" insertafter="tasksMenuMail, tasksMenuNavigator" label="&IMCmd.label;" accesskey="&IMCmd.accesskey;" key="key_im" command="Tasks:IM" class="menuitem-iconic icon-aim16"/>
  28.   </menupopup>
  29.   
  30.   <statusbarpanel  id="component-bar">
  31.     <toolbarbutton class="taskbutton" id="mini-aim" insertbefore="mini-comp" 
  32.             tooltip="aTooltip" tooltiptext="&IMCmd.tooltip;"
  33.             oncommand="toOpenWindowByType('Aim:AimApp', 'chrome://aim/content/App.xul');">
  34.     </toolbarbutton>
  35.   </statusbarpanel >
  36.  
  37. <script type="application/x-javascript">
  38.   <![CDATA[
  39.  
  40.  
  41. var instaimTaskObserver = null;
  42.  
  43. function aimTaskObserver()
  44. {
  45. }
  46.  
  47. aimTaskObserver.prototype.observe = function(subject, message, data) {
  48.     if (message == 'sessionState-changed')  {
  49.         UpdateTaskImage(data);
  50.     }
  51.     if (message == 'sessionMode-changed') {
  52.         ChangeTaskImage(data);
  53.      }
  54.     if (message == 'quit-application') {
  55.       aimPrefsManager().SetBoolPref("aim.session.appfirstlogin",true,null, true);
  56.     }
  57. }
  58.  
  59.  
  60.  
  61. /*
  62.   * Name: UpdateTaskImage(stateMsg)
  63.   * Arguments: stateMsg - obtained passed from the observe code above. This contains the state information
  64.   * Description: This function will change the task bar aim icon online-state attribute based on the input stateMsg. The css rules
  65.   * will then take into effect and up[date the icon appropriately.
  66.   * Author: Prassanna prass@netscape.com
  67. */
  68.  
  69. function UpdateTaskImage(stateMsg)
  70. {
  71.    var taskIcon= window.document.getElementById("mini-aim");  
  72.    if (taskIcon)
  73.    {
  74.    switch (stateMsg) {
  75.     case "Offline": taskIcon.setAttribute("online-state", "offline"); break;
  76.     case "Online": taskIcon.setAttribute("online-state", "online"); break;
  77.     case "OnlineAway":  taskIcon.setAttribute("online-state", "away"); break;
  78.     default:  taskIcon.setAttribute("online-state", "offline");
  79.    }
  80.    }
  81. }
  82.  
  83.  
  84. /*
  85.   * Name: initializeTaskIcon()
  86.   * Arguments: none
  87.   * Description:
  88.   * This function is called a new window is loaded. This will initialize the aim task bar icon with the aimsession's current State
  89.   * when the current window is loading.
  90.   * Author: Prassanna prass@netscape.com
  91. */
  92.  
  93. function initializeTaskIcon()
  94. {
  95.   var pIAimManager=Components.classes['@netscape.com/aim/IMManager;1'].getService(Components.interfaces.nsIIMManager);
  96.   var pIAimSession = pIAimManager.QueryInterface(Components.interfaces.nsIAimSession);
  97.   var pState = eval(pIAimSession.CurrentState);
  98.   var taskIcon = window.document.getElementById("mini-aim");  
  99.   var windowIcon = window.document.getElementById("IMMenuItem");
  100.   var ptIcon= window.document.getElementById("AimPT-button");
  101.   if (taskIcon && windowIcon) {
  102.       var SessionType= getCurrentSessionType();
  103.       if (SessionType == "ICQ")
  104.       {
  105.         taskIcon.setAttribute("sessionMode", "Icq");
  106.         windowIcon.setAttribute("class","menuitem-iconic icon-icq16");
  107.         if (ptIcon) {
  108.           ptIcon.setAttribute("sessionMode","Icq");
  109.           ptIcon.setAttribute("label","ICQ");
  110.         }
  111.       }
  112.       else
  113.       {
  114.         taskIcon.setAttribute("sessionMode", "Aim");
  115.         windowIcon.setAttribute("class","menuitem-iconic icon-aim16");
  116.         if (ptIcon) {
  117.           ptIcon.setAttribute("sessionMode","Aim");
  118.           ptIcon.setAttribute("label","AIM");
  119.           }
  120.       }
  121.   switch (pState) {
  122.     case 1: taskIcon.setAttribute("online-state", "offline"); break;
  123.     case 8: taskIcon.setAttribute("online-state", "online"); break;
  124.     case 9: taskIcon.setAttribute("online-state", "away"); break;
  125.     default: taskIcon.setAttribute("online-state", "offline");
  126.   }
  127.   }      
  128. }
  129.  
  130. /*
  131.   * Name: checkAimAutoLogin()
  132.   * Arguments: none
  133.   * Description:
  134.   * This function is called everytime a component window( like nav, mail etc.) who can invoke an IM window
  135.   * from their New menu is loaded. The purpose of this function is to autologin to aim if autologin preference is set.
  136.   * There is a global pref - appfirstlogin which is true if the user is launching the app and
  137.   * user has not signed to aim yet. If it is true, then the DoLogin function is called. The timeout is to take care
  138.   * of the delay in loading sidebar buddylist panel.
  139. */
  140.  
  141. function checkAimAutoLogin()
  142. {
  143.   var first= aimPrefsManager().GetBoolPref("aim.session.appfirstlogin", null,true);
  144.   /* If user had already chosen to signoff in some sidebar after the app is launched */
  145.   if (first == false )
  146.       return;
  147.   setTimeout("DoLogin()", 1000);
  148. }
  149.  
  150.  
  151.  
  152. function ChangeTaskImage(Msg)
  153. {
  154.    var taskIcon= window.document.getElementById("mini-aim");  
  155.    var windowIcon = window.document.getElementById("IMMenuItem");  
  156.    var ptIcon= window.document.getElementById("AimPT-button");
  157.    if (taskIcon && windowIcon)
  158.    {
  159.    switch (Msg) {
  160.     case "Aim": taskIcon.setAttribute("sessionMode", "Aim");
  161.                 windowIcon.setAttribute("class","menuitem-iconic icon-aim16");
  162.                 if (ptIcon) {
  163.                   ptIcon.setAttribute("sessionMode","Aim");
  164.                   ptIcon.setAttribute("label","AIM");
  165.                   }
  166.                 break;
  167.     case "Icq": taskIcon.setAttribute("sessionMode", "Icq");
  168.                 windowIcon.setAttribute("class","menuitem-iconic icon-icq16");
  169.                 if (ptIcon) {
  170.                   ptIcon.setAttribute("sessionMode","Icq");
  171.                   ptIcon.setAttribute("label","ICQ");
  172.                   }
  173.                 break;
  174.     default:    var SessionType= getCurrentSessionType();
  175.                 if (SessionType == "ICQ")
  176.                 {
  177.                   taskIcon.setAttribute("sessionMode", "Icq");
  178.                   windowIcon.setAttribute("class","menuitem-iconic icon-icq16");
  179.                   if (ptIcon) {
  180.                     ptIcon.setAttribute("sessionMode","Icq");
  181.                     ptIcon.setAttribute("label","ICQ");
  182.                     }
  183.                 }
  184.                 else
  185.                 {
  186.                   taskIcon.setAttribute("sessionMode", "Aim");
  187.                   windowIcon.setAttribute("class","menuitem-iconic icon-aim16");
  188.                   if (ptIcon) {
  189.                     ptIcon.setAttribute("sessionMode","Aim");
  190.                     ptIcon.setAttribute("label","AIM");
  191.                     }
  192.                 }
  193.                 break;
  194.     }
  195.   }
  196. }
  197. /*
  198.   * Name: DoLogin()
  199.   * Arguments: none
  200.   * Description:
  201.   * This function checks to see if aim sidebar panel is clicked or  loaded on top in which case, 
  202.   * this just returns (since sidebar aim panel can take care of this scenario) 
  203.   * It checks to see if all the necessary data for autologin is present,
  204.   * If and only if all data is present, then the user is signed onto aim service. 
  205.   * (This scenario happens when the aim sidebar panel is collapsed but the user had used aim before and set up
  206.   * the autologin pref to be true and has never login to aim this time of launch.)
  207.   * Return Value: none
  208. */
  209.  
  210. function DoLogin()
  211. {
  212.   var panelset=document.getElementById("sidebar-panels");
  213.   for (var i=0; i<panelset.childNodes.length-1; i+=2) {
  214.     var panel=panelset.childNodes.item(i);
  215.     if (panel.getAttribute('id') == "urn:sidebar:panel:im-panel"){
  216.       if (panel.getAttribute('selected')) {
  217.         //already as top selected panel in sidebar - sidebar window load will do the rest-just return
  218.         return;
  219.       }
  220.     }
  221.   }
  222.   var pIAimManager=Components.classes['@netscape.com/aim/IMManager;1'].getService(Components.interfaces.nsIIMManager);
  223.   var pIAimSession = pIAimManager.QueryInterface(Components.interfaces.nsIAimSession);
  224.   
  225.   //user already logged in - just return
  226.   var isOnline = pIAimSession.IsOnline();
  227.   if ( isOnline == true )
  228.     return;
  229.   
  230.   var autoLogin = aimPrefsManager().GetBoolPref("aim.session.autologin", null, false);
  231.   if (!autoLogin)
  232.    return;
  233.   
  234.   var screenName = aimPrefsManager().GetCharPref("aim.session.screenname", null, true);
  235.   if (!screenName || screenName == '')
  236.     return;
  237.    
  238.   var connectionName = aimPrefsManager().GetCharPref("aim.session.connectionname", null, false);
  239.   if (!connectionName || connectionName == '')
  240.     return;
  241.  
  242.    
  243.   if (!IsServiceCorrect(screenName, connectionName)) {
  244.     return;  
  245.   }
  246.  
  247.   if(pIAimSession)
  248.   {
  249.     var password = pIAimSession.GetSavedPassword(screenName);
  250.     if (!password || password == '')
  251.       return;    
  252.  
  253.     setConnectionInfo (connectionName, "im");
  254.     
  255.     pIAimSession.Login(screenName, password, getsidebarframe());
  256.     
  257.       return;
  258.   }
  259. }
  260.  
  261. function Init()
  262. {
  263.    var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  264.    observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  265.     if (observerService) {
  266.       instaimTaskObserver = new aimTaskObserver();
  267.     }
  268.     if (observerService && instaimTaskObserver) {
  269.       observerService.addObserver(instaimTaskObserver, "quit-application", false);
  270.       observerService.addObserver(instaimTaskObserver,"sessionState-changed", false);
  271.       observerService.addObserver(instaimTaskObserver,"sessionMode-changed", false);
  272.     } else {
  273.       instaimTaskObserver=null;
  274.     }
  275.  
  276.   // if there is a sidebar, check for aim auto login
  277.   if (document.getElementById('sidebar-box'))
  278.     checkAimAutoLogin();
  279.  
  280.   // initialize the aim task icon to the current icon state
  281.   initializeTaskIcon();
  282.  
  283.   // Remove the observers during unload
  284.   window.addEventListener("unload", Uninit, false); 
  285. }
  286.  
  287.  
  288. function Uninit()
  289. {
  290.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  291.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  292.   if (observerService  && instaimTaskObserver)
  293.     {
  294.       observerService.removeObserver(instaimTaskObserver, "quit-application");
  295.       observerService.removeObserver(instaimTaskObserver,"sessionState-changed");
  296.       observerService.removeObserver(instaimTaskObserver,"sessionMode-changed");
  297.       //instaimTaskObserver=null;
  298.     }
  299. }
  300.  
  301.  
  302.  
  303. window.addEventListener("load", Init, false); 
  304.  
  305.   
  306.  
  307. ]]>
  308. </script>         
  309.  
  310. </overlay>
  311.